package us.wili.dev.third.util.example.config;

import cn.jpush.api.JPushClient;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import us.wili.dev.common.util.jiguang.JiGuangProperties;

/**
 * author: lefore
 * date: 2018/9/30
 */
@Configuration
@EnableConfigurationProperties(JiGuangConfig.JiGuangPropertiesCreator.class)
public class JiGuangConfig {

    @Bean
    public JPushClient jPushClient(JiGuangPropertiesCreator propCreator) {
        JiGuangProperties prop = propCreator.getJiguang();
        return new JPushClient(prop.getMasterSecret(), prop.getAppKey());
    }

    @ConfigurationProperties
    public static class JiGuangPropertiesCreator {

        private JiGuangProperties jiguang;

        public JiGuangProperties getJiguang() {
            return jiguang;
        }

        public void setJiguang(JiGuangProperties jiguang) {
            this.jiguang = jiguang;
        }
    }
}
